package com.sky.mapper;

import com.sky.entity.AddressBook;
import com.sky.result.Result;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {


    //个人中心里的地址管理（查询登录人地址管理）
    @Select("select * from address_book where user_id=#{userId} ")
    List<AddressBook> list(Long userId);


    void insert(AddressBook addressBook);

    //将当前用户的收货地址默认为非默认
    @Update("update address_book set is_default=0 where user_id=#{userId}")
    void allNotDefault(Long userId);
    //根据地址id设置isdefault=1更新当前id为默认
    @Update("update address_book set is_default=1 where id=#{id}")
    void getUpdateDefault(AddressBook addressBook);


    //查询默认收货地址
    @Select("select * from address_book where user_id=#{userId} and is_default=1")
    AddressBook getDefault(Long currentId);

    //回显地址簿信息
    @Select("select  * from address_book where id=#{addressBookId}")
    AddressBook getById(Long addressBookId);

    //保存地址
    void updateById(AddressBook addressBook);
}

